﻿Imports System.Collections.ObjectModel
Imports System.Collections.Specialized
Imports System.ComponentModel

Public Class Main
    Public WithEvents oWindowList As OpenedWindowList = OpenedWindowList.GetList()
    Private WithEvents oWindow As OpenedWindowClass

#Region "Window Events"
    Private Sub Main_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Closed
        Application.Current.Shutdown()
    End Sub

    Private Sub Main_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Dim gwf As New WeatherClass
        Dim asf As String = gwf.GetWeatherForecast("http://webservice.theweather.com.au/ws1/wx.php?lt=aploc&fc=1&pc=6000&days=3&rollover=24&u=13409", "2560", 5, "../../weather resources/weather.xslt")
        'ExpanderText.Text = "Weather for "
    End Sub
#End Region

#Region "RibbonButton Events"

    Private Sub ButtonExpense_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles ButtonExpense.Click
        Dim expenseWindow As New ExpensesWindow
        expenseWindow.Name = "window" & oWindowList.Count
        expenseWindow.Show()

        'Dim rbutton As New RibbonButton
        'rbutton.Name = "xxx"
        'rbutton.Label = expenseWindow.Title
        'rbutton.LargeImageSource = New BitmapImage(New Uri("Images/shopping_trolley-32.png", UriKind.Relative))


        oWindow = New OpenedWindowClass(expenseWindow.Name, "Expenses", expenseWindow.Name, "Images/shopping_trolley-32.png")
        HookupChangeEventHandler(oWindow)
        oWindowList.Add(oWindow)

        'OpenedWindow.Items.Add(rbutton)
    End Sub
    Private Sub ButtonIncome_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles ButtonIncome.Click
        Dim incomeWindow As New IncomeWindow
        incomeWindow.Name = "window" & oWindowList.Count
        incomeWindow.Show()

        'Dim rbutton As New RibbonButton
        'rbutton.Name = "xxx"
        'rbutton.Label = expenseWindow.Title
        'rbutton.LargeImageSource = New BitmapImage(New Uri("Images/shopping_trolley-32.png", UriKind.Relative))


        oWindow = New OpenedWindowClass(incomeWindow.Name, "Income", incomeWindow.Name, "Images/saving-32.png")
        HookupChangeEventHandler(oWindow)
        oWindowList.Add(oWindow)
    End Sub
#End Region

#Region "Support Procedures"

    Private Sub HookupChangeEventHandlers()
        ' Hook up change notification. This really
        ' isn't part of the ObservableCollection class,
        ' but it seems that you would want to know
        ' how to track modifications in the 
        ' properties of the children of the collection:
        For Each oWindow As OpenedWindowClass In oWindowList
            HookupChangeEventHandler(oWindow)
        Next
    End Sub

    Private Sub HookupChangeEventHandler(ByVal oWindow As OpenedWindowClass)
        ' Add a PropertyChanged event handler for 
        ' the specified Customer instance:
        AddHandler oWindow.PropertyChanged, _
          AddressOf HandlePropertyChanged
    End Sub

    Private Sub SetupData()
        HookupChangeEventHandlers()
    End Sub

    Private Sub RibbonButtonExpense_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)


        For itemIndex = 0 To Application.Current.Windows.Count - 1
            If Application.Current.Windows(itemIndex).Name = sender.tag Then
                Application.Current.Windows(itemIndex).Activate()
            End If

        Next


    End Sub

    
#End Region

#Region "Change Event Handlers"

    Private Sub HandlePropertyChanged( _
    ByVal sender As Object, _
    ByVal e As PropertyChangedEventArgs)

        Dim propName As String = e.PropertyName
        Dim myWindow As OpenedWindowClass = CType(sender, OpenedWindowClass)


        Dim propInfo As System.Reflection.PropertyInfo = _
          GetType(OpenedWindowClass).GetProperty(propName)
        Dim value As Object = _
          propInfo.GetValue(myWindow, Nothing)
    End Sub

    Private Sub Data_CollectionChanged( _
      ByVal sender As Object, _
      ByVal e As NotifyCollectionChangedEventArgs) _
      Handles oWindowList.CollectionChanged

        If e.Action = NotifyCollectionChangedAction.Add Or _
          e.Action = NotifyCollectionChangedAction.Remove Then

        End If
    End Sub

#End Region

    
End Class
